
import PropertyType from './propertyType';

export default class Point implements PropertyType {
    public x: number;
    public y: number;
    constructor(x?, y?) {
        this.x = x ? x : 0;
        this.y = y ? y : 0;
    }

    public static readonly REG_EX = /^([\-0-9\.]+)\,([\-0-9\.]+)$/;

    static fromString(literal): any {
        var point = new Point();
        if (literal.match(Point.REG_EX)) {
            point.x = parseFloat(RegExp.$1);
            point.y = parseFloat(RegExp.$2);
        }

        return point;
    };

    toString() {
        return this.x + "," + this.y;
    };

    applyExpressionX(value) {
        this.x = value;
    };

    applyExpressionY(value) {
        this.y = value;
    };

    translate(dx, dy) {
        return new Point(this.x + dx, this.y + dy);
    };
}

pencilSandbox.Point = {
    newPoint: function (x, y) {
        return new Point(x, y);
    }
};
for (var p in Point) {
    pencilSandbox.Point[p] = Point[p];
};
